package com.xmall.controller.wx;

import com.xmall.bean.bo.GoodsListBo;
import com.xmall.bean.vo.BaseRespVo;
import com.xmall.bean.vo.GoodsRelatedVo;
import com.xmall.bean.vo.WxGoodsCategoryVo;
import com.xmall.bean.vo.WxGoodsListVo;
import com.xmall.bean.vo.goodsdetail.GoodsDetailVo;
import com.xmall.service.GoodsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController("wxGoodsController")
@RequestMapping("/wx/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @GetMapping("count")
    public BaseRespVo countGoods() {
        Integer total = goodsService.countGoods();
        Map<String, Integer> map = new HashMap<>(16);
        map.put("goodsCount", total);
        return BaseRespVo.ok(map);
    }

    @GetMapping("category")
    public BaseRespVo queryCategory(Integer id) {
        WxGoodsCategoryVo wxGoodsCategoryVo = goodsService.queryCategory(id);
        return BaseRespVo.ok(wxGoodsCategoryVo);
    }

    @GetMapping("list")
    public BaseRespVo list(GoodsListBo goodsListBo) {
        WxGoodsListVo wxGoodsListVo = goodsService.queryGoodsListSelective(goodsListBo);
        return BaseRespVo.ok(wxGoodsListVo);
    }

    @GetMapping("detail")
    public BaseRespVo detail(Integer id) {
        GoodsDetailVo goodsDetailVo = goodsService.queryGoodsDetails(id);
        return BaseRespVo.ok(goodsDetailVo);
    }

    @GetMapping("related")
    public BaseRespVo related(Integer id) {
        GoodsRelatedVo goodsRelatedVo = goodsService.queryRelatedGoods(id);
        return BaseRespVo.ok(goodsRelatedVo);
    }

}
